package com.cskaoyan.crud;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;

/**
 * 创建日期: 2022/11/22 17:08
 *
 * @author ciggar
 */
public class InsertDemo {


    public static void main(String[] args) throws IOException {

        // 1. 获取一个SqlSessionFactoryBuilder
        SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();

        // 2. 获取SqlSessionFactory
        SqlSessionFactory sqlSessionFactory = builder.build(Resources.getResourceAsStream("mybatis-config.xml"));

        // 3. 获取SqlSession
        SqlSession sqlSession = sqlSessionFactory.openSession(true);

        // 4. 执行SQL语句
        int affectedRows = sqlSession.update("cskaoyan.insert");

        // 5. 输出影响的行数
        System.out.println("affectedRows:" + affectedRows);

        // 6. 关闭资源
        sqlSession.close();

    }
}
